package com.itheima.edu.info.manger.dao;

import com.itheima.edu.info.manger.domain.Student;
import com.itheima.edu.info.manger.service.StudentService;

public class StudentDao {
    private static Student[] stus = new Student[5];
    static {
        Student stu1=new Student("22","张三","44","44444");
     Student stu2=new Student("255","张","48","44444");
     stus[0]=stu1;
     stus[0]=stu2;
    }
    public boolean addtudent(Student stu) {

        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            stus[index] = stu;
            return true;
        }

    }

    public Student[] findstudentid() {
        return stus;
    }

    public void deleteid(String deid) {
        //查找ID所在索引位置
      int index=gitid(deid);
        //将索引位置用NULL覆盖
        stus[index]=null;
    }
    public  int gitid(String id){
                int index=-1;
                for (int i = 0; i < stus.length; i++) {
                    Student stu=stus[i];
                    if(stu !=null && stu.getId().equals(id)){
                        index=i;
                        break;
                    }
        }
return index;
    }

    public void updatastudent(String upid, Student sutnew) {
        //查找updatastudent的索引位置
        int index= gitid(upid);
        //将索引位置使用新的信息替换
    stus[index]=sutnew;
    }
}

